﻿using System;

namespace _1323_maximum_69_number
{
    class Program
    {
        static void Main (string[] args)
        {
            Console.WriteLine (new Solution().Maximum69Number(6696));

            Console.WriteLine ();
        }
    }

    public class Solution
    {
        public int Maximum69Number (int num)
        {
            if(num/1000 == 6)
            {
                num += 3000;
            }
            else if ((num /100)%10 == 6)
            {
                num += 300;
            }
            else if ((num / 10)%10 == 6)
            {
                num += 30;
            }
            else if (num%10 == 6)
            {
                num += 3;
            }

            return num;
        }
    }
}
